package com.aegis.manage.controller.sys;

import com.aegis.common.mybatis.base.BaseController;
import com.aegis.common.mybatis.model.PageResult;
import com.aegis.manage.api.request.AddRoleRequest;
import com.aegis.manage.api.request.UpdateRoleRequest;
import com.aegis.manage.api.vo.SysRoleVO;
import com.aegis.manage.model.dos.SysRole;
import com.aegis.manage.service.sys.role.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author renogo
 *
 * @Version 1.0
 * @Descritube
 */
@RestController
@RequestMapping("/sys/role")
@Api(tags = "系统-角色管理")
public class SysRoleController extends BaseController<SysRoleService> {


    @ApiOperation(value = "添加角色", notes = "添加角色")
    @PostMapping("/add")
    public String addRole(@RequestBody @Validated AddRoleRequest request) {
        return getService().addRole(request);
    }


    @ApiOperation(value = "更新角色", notes = "更新角色")
    @PutMapping("/update")
    public void updateRole(@RequestBody @Validated UpdateRoleRequest request) {
        getService().updateRole(request);
    }

    @ApiOperation(value = "查询角色分页", notes = "查询角色分页")
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页码", required = false),
            @ApiImplicitParam(name = "size", value = "每页数据量", required = false),
            @ApiImplicitParam(name = "keywords", value = "检索关键词", required = false),
    })
    public PageResult<SysRoleVO> selectRolePage(@RequestParam(required = false, defaultValue = "1") int current,
                                                @RequestParam(required = false, defaultValue = "10") int size,
                                                @RequestParam(required = false) String keywords) {
        PageResult<SysRole> sysRoleDOPageResult = getService().selectRolePage(current, size, keywords);
        return sysRoleDOPageResult.convert(sysRoleDO -> {
            SysRoleVO sysRoleVO = new SysRoleVO();
            return (SysRoleVO) sysRoleVO.convert(sysRoleDO);
        });
    }

    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "角色id", required = false),
    })
    @DeleteMapping("/del")
    public void delRole(@RequestParam("id") String id) {
        getService().delRole(id);
    }


}
